package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.dubbo.api.QuestionApi;
import com.tanhua.dubbo.mapper.QuestionMapper;
import com.tanhua.model.domain.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author Pan Rundong
 * @Date 2023-02-27 9:44
 * @Desc 问题表Api实现类
 */
@DubboService
public class QuestionApiImpl implements QuestionApi {
    @Autowired
    private QuestionMapper questionMapper;

    /**
     * 根据Id查询
     * @Author: Pan Rundong
     * @param userId
     * @return com.tanhua.model.domain.Question
     */
    @Override
    public Question getById(Long userId) {
        LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Question::getUserId, userId);
        Question question = questionMapper.selectOne(queryWrapper);
        return question;
    }

    /**
     * 保存问题
     * @Author: Pan Rundong
     * @param question
     * @return void
     */
    @Override
    public void save(Question question) {
        questionMapper.insert(question);
    }

    /**
     * 更新问题
     * @Author: Pan Rundong
     * @param question
     * @return void
     */
    @Override
    public void update(Question question) {
        questionMapper.updateById(question);
    }
}
